package com.lineage.data.item_etcitem.wand;

import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.datatables.DropTable;
import com.lineage.server.datatables.ItemTable;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1MonsterInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1Object;
import com.lineage.server.serverpackets.S_DoActionGFX;
import com.lineage.server.serverpackets.S_NPCTalkReturn;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.templates.L1Drop;
import com.lineage.server.templates.L1Item;
import com.lineage.server.world.World;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class Npc_Wand extends ItemExecutor {
  public static ItemExecutor get() {
    return new Npc_Wand();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    int spellsc_objid = data[0];
    useNpcCarriedItemsWand(pc, spellsc_objid, item);
  }
  
  private void useNpcCarriedItemsWand(L1PcInstance pc, int targetId, L1ItemInstance item) {
    L1Object target = World.get().findObject(targetId);
    if (target == null)
      return; 
    pc.sendPacketsAll((ServerBasePacket)new S_DoActionGFX(pc.getId(), 17));
    if (target instanceof L1MonsterInstance) {
      L1MonsterInstance l1MonsterInstance = (L1MonsterInstance)target;
      ArrayList<L1Drop> dropList = DropTable.get().getdroplist(l1MonsterInstance.getNpcId());
      if (dropList != null) {
        String msg0 = l1MonsterInstance.getName();
        int m = l1MonsterInstance.getLevel();
        int n = l1MonsterInstance.getMaxHp();
        int i1 = l1MonsterInstance.getMaxMp();
        int i2 = l1MonsterInstance.getAc();
        String[] msgs = { msg0, m+"", n+"", i1+"", i2+"" };
        Map<Integer, String> msgstable = new HashMap<>();
        int i = 0;
        while (i < msgs.length) {
          msgstable.put(Integer.valueOf(i), msgs[i]);
          i++;
        } 
        String[] itemdatas = new String[dropList.size()];
        int j = 0;
        while (j < itemdatas.length) {
          L1Drop drop = dropList.get(j);
          L1Item dropitem = ItemTable.get().getTemplate(drop.getItemid());
          itemdatas[j] = dropitem.getName();
          msgstable.put(Integer.valueOf(j + 5), itemdatas[j]);
          j++;
        } 
        String[] msgs2 = new String[msgstable.size()];
        int k = 0;
        while (k < msgstable.size()) {
          msgs2[k] = msgstable.get(Integer.valueOf(k));
          k++;
        } 
        pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(pc.getId(), "mobdroplist", msgs2));
      } else {
        pc.sendPackets((ServerBasePacket)new S_SystemMessage("此怪物没有掉宝资料。"));
      } 
    } else {
      pc.sendPackets((ServerBasePacket)new S_SystemMessage("只能对怪物使用。"));
    } 
  }
}
